#!/usr/bin/python
# -*- coding: utf-8 -*
from stackDemo import Stack

parentheses = ['((((((())', '()))', '(()()(()', '()()()', '(()()']


def check_balence(pString):
    s = Stack()
    for i in range(len(pString)):
        if pString[i]=='(':
            s.push(i)
        else:
            if not s.isEmpty():
                s.pop()
            else:
                return False
    return s.isEmpty()


for pt in parentheses:
    print(check_balence(pt))

